package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.common.VideoSentenceDataBean;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by hyy on 2017/12/16.
 * describe as
 */

public class CartoonSentenceAdapter extends CommonRecycleViewAdapter<VideoSentenceDataBean> {

    private int onSelected = 0;
    private int onOldSelected = 0;

    public CartoonSentenceAdapter(Context mContext, List<VideoSentenceDataBean> itemDatas) {
        super(mContext, R.layout.cartoon_sentence_item, itemDatas);
    }


    @Override
    public void bindView(CustomViewHold customViewHold, VideoSentenceDataBean item, final int position) {
        TextView content = customViewHold.getView(R.id.content);
//        if (position == onSelected) {
//            content.setBackgroundColor(Color.parseColor("#FFFFFF"));
//        } else {
//            content.setBackgroundColor(Color.parseColor("#FFEDBE"));
//        }

        content.setText(item.getTranslation());
        content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onOldSelected = onSelected;
                onSelected = position;
                notifyItemChanged(onSelected);
                notifyItemChanged(onOldSelected);

                if (sentenceOnclickBack != null) {
                    sentenceOnclickBack.onClickCallBack(onSelected);
                }
            }
        });
//
//        SimpleDraweeView record_icon = customViewHold.getView(R.id.record_icon);
//        record_icon.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                sentenceOnclickBack.onRecordCallBack(null);
//            }
//        });
//
//
//        SimpleDraweeView voice_icon = customViewHold.getView(R.id.voice_icon);
//        voice_icon.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                sentenceOnclickBack.onVoiceCallBack(null);
//            }
//        });
//
//
//        SimpleDraweeView play_icon = customViewHold.getView(R.id.play_icon);
//        play_icon.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                sentenceOnclickBack.onPlayCallBack(null);
//            }
//        });
    }


    private SentenceOnclickBack sentenceOnclickBack;


    public void setSentenceOnclickBack(SentenceOnclickBack sentenceOnclickBack) {
        this.sentenceOnclickBack = sentenceOnclickBack;
    }

    public interface SentenceOnclickBack {
        abstract void onClickCallBack(int onSelected);

        abstract void onRecordCallBack(SimpleDraweeView simpleDraweeView);

        abstract void onVoiceCallBack(SimpleDraweeView simpleDraweeView);

        abstract void onPlayCallBack(SimpleDraweeView simpleDraweeView);
    }
}
